{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1631f7fc-cccf-4763-a447-283dd91f5e5f",
   "metadata": {},
   "source": [
    "## 演示KNN算法原理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a138b0d4-5b8d-4b8c-885f-96558eedec70",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4d74d86c-1062-49f9-8f1a-114a882045a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 样本特征\n",
    "data_X = [\n",
    "    [1.3, 6],\n",
    "    [3.5, 5],\n",
    "    [4.2, 2],\n",
    "    [5, 3.3],\n",
    "    [2, 9],\n",
    "    [5, 7.5],\n",
    "    [7.2, 4],\n",
    "    [8.1, 8],\n",
    "    [9, 2.5]\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7dae82cb-176c-45df-aff2-1821d2538d06",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 样本标记（类别）\n",
    "data_y = [0,0,0,0,1,1,1,1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6e99ca22-2ae6-449f-92b2-954330eb738e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 训练集\n",
    "X_train = np.array(data_X)\n",
    "y_train = np.array(data_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "14bd453b-7b4c-4b83-bd55-fcd55d5abbff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.3, 6. ],\n",
       "       [3.5, 5. ],\n",
       "       [4.2, 2. ],\n",
       "       [5. , 3.3],\n",
       "       [2. , 9. ],\n",
       "       [5. , 7.5],\n",
       "       [7.2, 4. ],\n",
       "       [8.1, 8. ],\n",
       "       [9. , 2.5]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "546833f0-717e-4de5-888d-833a557c3c69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0, 0, 1, 1, 1, 1, 1])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "53bdc1e1-1e48-4333-8149-a49b456583bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True,  True,  True, False, False, False, False, False])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6f5fe30c-bfcc-4c06-8b51-84ec26cf48f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.3, 3.5, 4.2, 5. ])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回的是一个包含所有标签为 0 的样本的 第一个特征 的一维数组\n",
    "# 第二个索引（0）指定了从 X_train 中提取这些样本的 第一个特征（即索引为 0 的列）\n",
    "X_train[y_train == 0,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b0ec881f-be13-4156-bedc-6b9a3057ebc7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([6. , 5. , 2. , 3.3])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回的是一个包含所有标签为 0 的样本的 第二个特征 的一维数组\n",
    "X_train[y_train == 0, 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c8338a9d-e1e4-4f6a-a823-d177d3da6184",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhE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fbtycnLsHilpLMtSOBy2ewzjJk2apN27d8dsmzt3roYNG6aFCxf22G9OhMNh7dmzR+PHj7d7FOPGjh3b6mvg+/bt0+DBg22aKPFWrVql9PR0TZ061e5REuKLL75QSkrsUkKn09kjv27apH///urfv7+OHj2qLVu26Oc//3nSZ7A1LI4fP64DBw403z948KB27dqlAQMGKCsry8bJzCopKdG6dev0wgsvyOVy6bPPPpMkeTwepaWl2TydOffff7+uvvpq+Xw+hUIhrV+/Xtu3b1dlZaXdoxnncrlarZHp37+/Bg4c2KPWztx7772aNm2asrKydOTIES1evFjBYFBz5syxezTj7rnnHuXn5+vxxx/XzJkz9c4772jFihVasWKF3aMlRGNjo1atWqU5c+aoT5+e+d+Y06ZN05IlS5SVlaURI0bo/fff11NPPaV58+bZPZpxW7ZskWVZGjp0qA4cOKAf//jHGjp0qObOnZv8YZJ+jKSF1157zZLU6jZnzhw7xzKurfcoyVq1apXdoxk1b948a/DgwVbfvn2t888/35o0aZL15z//2e6xkqYnrrH43ve+Z2VkZFhnnXWWlZmZaRUVFfXINTNNXnrpJWvkyJFWamqqNWzYMGvFihV2j5QwW7ZssSRZe/futXuUhAkGg1ZpaamVlZVl9evXz8rNzbUeeOABKxwO2z2acc8995yVm5tr9e3b17rwwgutkpIS69ixY7bMws+mAwAAY7iOBQAAMIawAAAAxhAWAADAGMICAAAYQ1gAAABjCAsAAGAMYQEAAIwhLAAAgDGEBQAAMIawAAAAxhAWAADAGMICAAAY839CdK3cw5p4ngAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 特征点离散图\n",
    "plt.scatter(X_train[y_train == 0,0],X_train[y_train == 0, 1],color=\"red\",marker=\"x\")\n",
    "plt.scatter(X_train[y_train == 1,0],X_train[y_train == 1, 1],color=\"green\",marker=\"o\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "27cd9917-ac9a-4df2-a0f4-243ea05ed81e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 新的样本点\n",
    "data_new = np.array([4,5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9ed541b4-231f-4874-a0c7-95fd5f2ad64c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAhYAAAGdCAYAAABO2DpVAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAAIvhJREFUeJzt3Xt00/X9x/FXGqRUTKIwKi1JacscIAz1HPhpuQgMZFXkoLUw8TIE3Y5nVYscN0Td1AlWd/HAzs5w4A6D8kNkrODtUIZOuuK1qDhUxsXimkKVbQeSgFtc0+/vj/xaGttCUz7Jt5fn45wcyTffkHe2M/Pc9/vJNw7LsiwBAAAYkGL3AAAAoPsgLAAAgDGEBQAAMIawAAAAxhAWAADAGMICAAAYQ1gAAABjCAsAAGBMr2S/YENDg44cOSKXyyWHw5HslwcAAB1gWZZCoZAyMzOVktL2cYmkh8WRI0fk8/mS/bIAAMAAv98vr9fb5uNJDwuXyyUpOpjb7U72ywMAgA4IBoPy+XxNn+NtSXpYNJ7+cLvdhAUAAF3MmZYxsHgTAAAYQ1gAAABjCAsAAGAMYQEAAIwhLAAAgDGEBQAAMIawAAAAxhAWAADAmKRfIKunijREVFlTqbpQnTJcGZqQNUHOFKfdYwEAYFTcRyxCoZAWLFigwYMHKy0tTWPHjlVVVVUiZus2yvaWKXt5tiavmaybym7S5DWTlb08W2V7y+weDQAAo+IOizvuuEPbt29XaWmp9uzZo2nTpmnq1Kk6fPhwIubr8sr2lqlwY6Fqg7Ux2w8HD6twYyFxAQDoVhyWZVnt3fnf//63XC6Xnn/+eU2fPr1p+6WXXqprr71WS5YsOePfEQwG5fF4FAgEuv1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ojR460UlNTrWHDhlkrV660e6SE2bZtmyXJ2rdvn92jJEwwGLSKi4utrKwsq0+fPlZubq714IMPWuFw2O7RjHvuuees3Nxcq3fv3tbAgQOtoqIi6/jx47bMws+mAwAAY7iOBQAAMIawAAAAxhAWAADAGMICAAAYQ1gAAABjCAsAAGAMYQEAAIwhLAAAgDGEBQAAMIawAAAAxhAWAADAGMICAAAY83+iEQP7WD3b5wAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X_train[y_train == 0,0],X_train[y_train == 0, 1],color=\"red\",marker=\"x\")\n",
    "plt.scatter(X_train[y_train == 1,0],X_train[y_train == 1, 1],color=\"green\",marker=\"o\")\n",
    "plt.scatter(data_new[0],data_new[1],color=\"blue\",marker=\"^\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40a7b19e-96df-4d71-b31a-a7f8db802081",
   "metadata": {},
   "source": [
    "## １．计算新样本点与已知样本的距离"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "8d4101f8-28d2-4804-81e0-48569a83b46a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.879236009777594\n",
      "0.5\n",
      "3.006659275674582\n",
      "1.9723082923316022\n",
      "4.47213595499958\n",
      "2.692582403567252\n",
      "3.3526109228480423\n",
      "5.080354318352215\n",
      "5.5901699437494745\n"
     ]
    }
   ],
   "source": [
    "for data in X_train:\n",
    "    print(np.sqrt(np.sum((data-data_new)**2)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6546624a-cc65-45ec-a2bd-e290006f9461",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 9])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test1= np.array([3,6])\n",
    "test2= np.array([2,3])\n",
    "test1+test2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "6bf7b211-fe95-41e7-a547-1f4f579f2163",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'array' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[16], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m array([])\n",
      "\u001b[0;31mNameError\u001b[0m: name 'array' is not defined"
     ]
    }
   ],
   "source": [
    "array([])    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "98a72b52-6eec-45ba-bd6f-af6165292fd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "test1=[1,2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "de0e3b21-f8dd-47f4-a230-904e3a183375",
   "metadata": {},
   "outputs": [],
   "source": [
    "test2=[3,2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "b9ff4b8c-8c62-48bd-a640-7dd1cca0125a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 2]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test1+test2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88e5a4c6-d67a-41f2-8f10-0a06251ecee8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
